package com.um.jdy.platform.order.manager;


import com.um.jdy.common.charge.service.OrderCommissionService;
import com.um.jdy.platform.order.entity.dto.CommissionSummaryPageDTO;
import com.um.jdy.platform.order.entity.vo.*;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.manager.BaseManager;
import com.um.springboot.starter.orm.params.PageParams;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 管理类：订单佣金表
 */
@Component
public class OrderCommissionManager extends BaseManager<OrderCommissionService> {

    /**
     * 查询充电订单佣金明细列表
     * @param id 订单ID
     * @return
     */
    public Response<List<OrderCommissionItemVO>> getCommissionList(String id){
        List<OrderCommissionItemVO> list = service.getViewModelList("get_charge_order_commissions",OrderCommissionItemVO.class,new Object[]{id});
//        CommissionSummaryVO summaryVO = service.getCMSViewModelBySqlName("get_merchant_charge_order_summary",CommissionSummaryVO.class,pageParams.getProperties(),pageParams.getValues(),
//                pageParams.getRangeEntitys());
        return Response.success(list);
    }

    /**
     * 分页查询运营商佣金明细
     * @param pageParams
     * @return
     */
    public Response<PartnersCommissionPageVO> getMerchantPage(PageParams pageParams){
        Page<PartnersCommissionItemVO> page = new Page<>();
        page.setPageNo(pageParams.getPageNo());
        page.setPageSize(pageParams.getPageSize());

        pageParams.getCondition().put("o.com_id",getComId());
        pageParams.getCondition().put("mm.type",pageParams.getCondition().get("type"));
        pageParams.getCondition().remove("type");
        pageParams.getCondition().put("o.status", "Completed");
        pageParams.getCondition().put("o.pay_status", "Payed");

        page = service.getCMSViewModelPageBySqlName(page,"get_merchant_order_commission_page","get_merchant_order_commission_count",PartnersCommissionItemVO.class,pageParams.getProperties(),pageParams.getValues(),
                pageParams.getRangeEntitys(),pageParams.getOrderNames(),pageParams.getSortOns());

        CommissionSummaryVO summaryVO = service.getCMSViewModelBySqlName("get_merchant_charge_order_summary",CommissionSummaryVO.class,pageParams.getProperties(),pageParams.getValues(),
                pageParams.getRangeEntitys());

        PartnersCommissionPageVO pageVO = new PartnersCommissionPageVO();
        pageVO.setPage(page);
        if(summaryVO != null){
            pageVO.setSummary(summaryVO);
        }
        return Response.success(pageVO);
    }



    /**
     * 分页查询运营商佣金统计
     * @param params
     * @return
     */
    public Response<Page<PartnersCommissionSummaryVO>> getMerchantSummaryPage(CommissionSummaryPageDTO params){
        Page<PartnersCommissionSummaryVO> page = new Page<>();
        page.setPageNo(params.getPageNo());
        page.setPageSize(params.getPageSize());

        Object[] values = new Object[]{params.getBeginTime(),params.getEndTime(),getComId(),params.getName(),params.getType(),getComId()};

        page = service.getViewModelPageBySqlName(page,"get_merchant_commission_summary_page","get_merchant_commission_summary_count",PartnersCommissionSummaryVO.class, values);

        return Response.success(page);
    }

}
